package com.ruoyi.fun.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fun.mapper.EcRefundMapper;
import com.ruoyi.fun.domain.EcRefund;
import com.ruoyi.fun.service.IEcRefundService;

/**
 * 退款/售后Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-06
 */
@Service
public class EcRefundServiceImpl implements IEcRefundService 
{
    @Autowired
    private EcRefundMapper ecRefundMapper;

    /**
     * 查询退款/售后
     * 
     * @param refundId 退款/售后主键
     * @return 退款/售后
     */
    @Override
    public EcRefund selectEcRefundByRefundId(Long refundId)
    {
        return ecRefundMapper.selectEcRefundByRefundId(refundId);
    }

    /**
     * 查询退款/售后列表
     * 
     * @param ecRefund 退款/售后
     * @return 退款/售后
     */
    @Override
    public List<EcRefund> selectEcRefundList(EcRefund ecRefund)
    {
        System.out.println("[DEBUG] EcRefundServiceImpl.selectEcRefundList - 查询参数 orgId: " + ecRefund.getOrgId());
        List<EcRefund> result = ecRefundMapper.selectEcRefundList(ecRefund);
        System.out.println("[DEBUG] EcRefundServiceImpl.selectEcRefundList - 查询结果数量: " + result.size());
        for (EcRefund refund : result) {
            System.out.println("[DEBUG] EcRefundServiceImpl.selectEcRefundList - 退款ID: " + refund.getRefundId() + ", orgId: " + refund.getOrgId());
        }
        return result;
    }

    /**
     * 新增退款/售后
     * 
     * @param ecRefund 退款/售后
     * @return 结果
     */
    @Override
    public int insertEcRefund(EcRefund ecRefund)
    {
        ecRefund.setCreateTime(DateUtils.getNowDate());
        // 不再强制设置orgId，使用Controller层传入的值
        // ecRefund.setOrgId(SecurityUtils.getDeptId());
        return ecRefundMapper.insertEcRefund(ecRefund);
    }

    /**
     * 修改退款/售后
     * 
     * @param ecRefund 退款/售后
     * @return 结果
     */
    @Override
    public int updateEcRefund(EcRefund ecRefund)
    {
        ecRefund.setUpdateTime(DateUtils.getNowDate());
        return ecRefundMapper.updateEcRefund(ecRefund);
    }

    /**
     * 批量删除退款/售后
     * 
     * @param refundIds 需要删除的退款/售后主键
     * @return 结果
     */
    @Override
    public int deleteEcRefundByRefundIds(Long[] refundIds)
    {
        return ecRefundMapper.deleteEcRefundByRefundIds(refundIds);
    }

    /**
     * 删除退款/售后信息
     * 
     * @param refundId 退款/售后主键
     * @return 结果
     */
    @Override
    public int deleteEcRefundByRefundId(Long refundId)
    {
        return ecRefundMapper.deleteEcRefundByRefundId(refundId);
    }

    /**
     * 根据refundId和组织ID查询Refund
     * 
     * @param refundId Refund主键
     * @param orgId 组织ID
     * @return Refund
     */
    @Override
    public EcRefund selectEcRefundByRefundIdAndOrgId(Long refundId, Long orgId)
    {
        return ecRefundMapper.selectEcRefundByRefundIdAndOrgId(refundId, orgId);
    }

    /**
     * 根据组织ID查询Refund列表
     * 
     * @param ecrefund Refund
     * @param orgId 组织ID
     * @return Refund集合
     */
    @Override
    public List<EcRefund> selectEcRefundListByOrgId(EcRefund ecrefund, Long orgId)
    {
        return ecRefundMapper.selectEcRefundListByOrgId(ecrefund, orgId);
    }
}